package com.wondertek.liveroom;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class SettingActivity extends ActionBarActivity implements OnClickListener {
	
	private ActionBar actionBar = null;
	
	private ImageView ivWifiPrompt;
	private ImageView ivWifiLook;
	private ImageView ivRecvMsg;
	
	private RelativeLayout ivAbout;
	private RelativeLayout ivUserAdvice;
	private RelativeLayout ivCheckVersion;
	
	private boolean flag= false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		initCtrl();
	}
	
	private void initCtrl() {
		actionBar = getSupportActionBar();
		actionBar.setDisplayShowTitleEnabled(true);
		actionBar.setTitle(R.string.activity_setting_title);
		actionBar.setHomeButtonEnabled(true);
		actionBar.setDisplayHomeAsUpEnabled(true);
		
//		ivWifiPrompt = (ImageView) findViewById(R.id.iv_setting_wifi_prompt);
//		ivWifiLook = (ImageView) findViewById(R.id.iv_setting_wifi_look);
//		ivRecvMsg = (ImageView) findViewById(R.id.iv_setting_push_message);
//		
//		this.ivWifiPrompt.setOnClickListener(this);
//		this.ivWifiLook.setOnClickListener(this);
//		this.ivRecvMsg.setOnClickListener(this);
		
		ivAbout = (RelativeLayout) findViewById(R.id.rl_setting_about);
		ivUserAdvice = (RelativeLayout) findViewById(R.id.rl_setting_user_advise);
		ivCheckVersion = (RelativeLayout) findViewById(R.id.rl_setting_update);
		
		this.ivAbout.setOnClickListener(this);
		this.ivUserAdvice.setOnClickListener(this);
		this.ivCheckVersion.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.setting, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		} else if(id == android.R.id.home) {
			this.finish();
			return true;
		}	
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View view) {
		int id = view.getId();
		switch(id) {
//		case R.id.iv_setting_push_message:
//			setImageViewLevel(this.ivRecvMsg);
//			break;
//		case R.id.iv_setting_wifi_prompt:
//			setImageViewLevel(this.ivWifiPrompt);
//			break;
//		case R.id.iv_setting_wifi_look:
//			setImageViewLevel(this.ivWifiLook);
//			break;
		case R.id.rl_setting_user_advise:
			Intent mintent = new Intent(SettingActivity.this, FeedBackActivity.class);
			this.startActivity(mintent);
			break;
			
		case R.id.rl_setting_about:
			Intent intent = new Intent(SettingActivity.this, AboutActivity.class);
			this.startActivity(intent);
			break;
		case R.id.rl_setting_update:
			break;
		}	
	}
	
	private void setImageViewLevel(ImageView view) {
		if(this.flag == false) {
			view.getDrawable().setLevel(1);
			this.flag = false;
		} else {
			view.getDrawable().setLevel(0);
			this.flag = true;
		}
	}
}
